<template>
    <div class="app-container">
        <el-row>
            <el-col :span="8">
                <el-form ref="form" :model="form" :rules="rules" label-position="right" label-width="180px">
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="当前账户可用余额：" prop="">
                                <div style="">
                                    {{ shopInfo.incomes }}
                                </div>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="收款账户：" prop="">
                                <el-select v-model="form.payWayId" placeholder="请选择" @change="selectChange">
                                    <el-option
                                        v-for="item in paywayList"
                                        :key="item.id"
                                        :label="item.accountName"
                                        :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="收款账户信息：" prop="">
                                <div>
                                    <div>{{ types[paywayInfo.types] }}</div>
                                    <div>{{ paywayInfo.account }}</div>
                                    <img v-if='paywayInfo.paywayCodeModel.url' :src="paywayInfo.paywayCodeModel.url" width="100px" height="100px">
                                </div>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="提现金额" prop="totalPrice">
                                <el-input v-model="form.totalPrice" type="number" style="width: 160px;" placeholder="请输入"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    
                    <el-form-item label="" prop="">
                        <el-button type="primary" @click="submit">预约提现</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>

<script>
 import { operateActionPost, operateActionGet } from '@/api/interface/operate.js'
export default {
    components: {  },
    data() {
        return {
            form: {},
            shopInfo: {},
            rules: {
                totalPrice: [{ required: true, message: '请输入转出金额', trigger: 'change' }],
            },
            paywayList: {},
            paywayInfo: {paywayCodeModel: {}},
            types: {
                'ali': '支付宝', 
                "wx": '微信',
                'bank': '银行卡'
            }
        }
    },
    created(){
        this.getShopInfo()
        this.getPaywayList()
    },
    methods: {
        selectChange(e){
            this.paywayList.map((item, index)=>{
                if(e == item.id){
                    this.paywayInfo = item
                }
            })
        },
        getShopInfo(){
            operateActionPost('/api/merchant/shop/getShopinfoByAdmin/', {}).then((res) => {
            if(res.data.code == 10000){
              this.shopInfo = res.data.data
            }
          })
        },
        getPaywayList(){
            operateActionGet('/api/system/paywayForShop/', {}).then((res) => {
            if(res.data.code == 10000){
                this.paywayList= res.data.data.list
            }
          })
        },
        submit(){
            this.$refs['form'].validate((valid) => {
              if (valid) {
                operateActionPost('/api/system/walletRecord/outMoneyForShop/', {
                    paywayType: 'incomes',
					payWayId: this.form.payWayId,
					payMoney: this.form.totalPrice,
                }).then((res) => {
                  if(res.data.code == 10000){
                    this.$message({
                      message: '已发起提现申请，预计两个工作日到账',
                      type: 'success'
                    })
                    this.$router.push({name: 'walletRecordForShopOutMoney'})
                  }
                })
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        }
       
    }
}
</script>

<style lang="scss" scoped>

</style>
